package com.test.baoxiudemo;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.test.baoxiudemo.battery.MyServicer;

public class MainActivity extends Activity implements OnClickListener {

	private Button mButtonBattery;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mButtonBattery = (Button) findViewById(R.id.button_battery);
		mButtonBattery.setOnClickListener(this);
		
		initBatteryStatus();
		
	}

	private void initBatteryStatus() {
		AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
		Intent intent = new Intent(this, MyServicer.class);
		intent.setAction("com.fbb.service");
		PendingIntent pendingIntent = PendingIntent.getService(this, 0,
				intent, PendingIntent.FLAG_UPDATE_CURRENT);
		long triggerAtTime = SystemClock.elapsedRealtime();
		am.setRepeating(AlarmManager.ELAPSED_REALTIME, triggerAtTime, 1000 * 60,
				pendingIntent);
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
	}

	@Override
	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.button_battery: {
			startActivity(new Intent(this, BatteryInfoActivity.class));
		}
		default:
			break;
		}
	}
}
